@extends('admin.layouts.header_other')
@section('title',"后台管理系统")
@section('content')
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script type="text/html" id="toolbarDemo">
        <div class="">
            <div class="layui-input-item">
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm padding_top" lay-event="countyInAdd">刷新</button>
                </div>
                <div  class="layui-inline">
                    <input type="text" name="title" placeholder="请输入用户" autocomplete="on" class="layui-input serach_input layui-btn-sm ">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm padding_top" >搜索</button>
                </div>
            </div>

        </div>
    </script>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="del">查看</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="{{asset('attach/js/layui.all.js')}}"></script>
    <script>
        layui.use('table', function(){
            var table = layui.table;
            table.render({
                elem: '#test'
                ,url:'{{route('admin.user.getlist')}}'
                ,toolbar: '#toolbarDemo'
                ,title: '后台用户管理'
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                    ,{field:'username', title:'用户名', width:150}
                    ,{field:'email', title:'邮箱', width:230, sort: true}
                    ,{field:'image', title:'用户图像', width:140, sort: true, templet:function (d) {
                       return "<img src='"+d.image+"' style='width:100px; height:100px;'>";

                    }}
                    ,{field:'mobile', title:'电话号码', width:150,sort:true}
                    ,{field:'sex', title:'性别',width:100,sort:true,templet:function (d) {
                            if(d.sex==1){
                                return "男"
                            }else{
                                return "女";
                            }
                        }}
                    ,{field:'is_open', title:'是否开启', width:105, templet:function (d) {
                            var str='';
                            str = "<input type='checkbox' name='is_open' value='"+d.is_open+"' lay-skin='switch' lay-text='屏蔽|开启' lay-filter='' ";
                            if(d.is_open==1){
                                str+="checked";
                            }
                            str+=">";
                            return str;

                    }}
                    ,{field:'ip', title:'IP',width:200}
                    ,{field:'created_at', title:'时间',width:200}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                ]]
                ,page: true
                ,loading:true
                ,size:'lg'
            });
            //头工具栏事件
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：'+ data.length + ' 个');
                        break;
                    case 'countyInAdd':
                        var openwin=layer.open({
                            type:2,
                            title:"后台用户",
                            content:'./adminUserAdd.html',
                            area:['100%','100%'],
                            maxmin:true,
                        });
                        layer.full(openwin);
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                //console.log(obj)
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    layer.prompt({
                        formType: 2
                        ,value: data.email
                    }, function(value, index){
                        obj.update({
                            email: value
                        });
                        layer.close(index);
                    });
                }
            });
        });
    </script>
@endsection